package com.motong.gongdan.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.motong.gongdan.constant.ColumnTypeIconMap;
import com.motong.gongdan.enums.ObjectType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 移动端卡片设置
 */
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "移动端卡片设置")
@Data
@Accessors(chain = true)
@TableName(value = "mobile_card_conf")
public class MobileCardConf extends PublicPo implements Serializable {
    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty(value = "id")
    private Long id;

    /**
     * 中文名称
     */
    @TableField(value = "cn_name")
    @ApiModelProperty(value = "中文名称")
    private String cnName;

    /**
     * 英文名称
     */
    @TableField(value = "en_name")
    @ApiModelProperty(value = "英文名称")
    private String enName;

    /**
     * 排序
     */
    @TableField(value = "sort")
    @ApiModelProperty(value = "排序")
    private Integer sort;

    /**
     * 所属模块(0 工单)
     */
    @TableField(value = "belong_module")
    @ApiModelProperty(value = "所属模块(0 工单)")
    private Integer belongModule;


    /**
     * 字段所属模块
     */
    @TableField(value = "column_module")
    @ApiModelProperty(value = "字段所属模块")
    private String columnModule;


    /**
     * 类型(0 标题, 1 元素, 2 封面)
     */
    @TableField(value = "type")
    @ApiModelProperty(value = "类型(0 标题, 1 元素, 2 封面)")
    private Integer type;

    /**
     * 创建人(user表id)
     */
    @TableField(value = "create_user")
    @ApiModelProperty(value = "创建人(user表id)")
    private Integer createUser;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;


    /**
     * 自定义字段id
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "customFieldId")
    private Integer customFieldId;

    @TableField(exist = false)
    @ApiModelProperty(value = "图标名称",hidden = true)
    private String iconName;

    @TableField(exist = false)
    @ApiModelProperty(value = "属性类型", hidden = true)
    private String customColumnType;

    public void setCustomColumnType(String customColumnType) {
        this.customColumnType = customColumnType;
        if (StringUtils.hasLength(customColumnType)){
            this.iconName = new ColumnTypeIconMap().getIconByName(ObjectType.workOrder.getCode(), customColumnType);
        }
    }

    private static final long serialVersionUID = 1L;
}